package message

import (
	accessToken "gitee.com/douxuefeng/go-utils/wechat/corp/access_token"
	"gitee.com/douxuefeng/go-utils/wechat/corp/config"
	"gitee.com/douxuefeng/go-utils/wechat/corp/params"
)

type message struct {
	cf *config.CorpConfig
}

func NewMessage(cf *config.CorpConfig) *message {
	return &message{cf: cf}
}

func (a *message) Send(p Policy) *params.MessageReply {
	token, err := accessToken.NewAccessToken(a.cf).GetAccessToken()
	if err != nil {
		return &params.MessageReply{Errmsg: err.Error(), Errcode: 1}
	}
	return p.Send(token)
}
